﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PTTK_HTTT_06.BUS;
using System.Data;

namespace PTTK_HTTT_06.DAO
{
    class SAN_PHAM_DB
    {
        public static List<SAN_PHAM> LayDanhSach()
        {
            DataProvider dataProvider = new DataProvider();
            string sqlStr = "select * from SAN_PHAM";
            if (!dataProvider.IsConnect())
                dataProvider.Connect();
            DataTable dt = dataProvider.ExcuteQueryDataTable(sqlStr);
            dataProvider.Disconnect();

            if (dt != null && dt.Rows.Count <= 0)
                return null;

            List<SAN_PHAM> SPList = new List<SAN_PHAM>();
            for (int i = 0, count = dt.Rows.Count; i < count; i++)
            {
                SAN_PHAM sp = new SAN_PHAM();
                sp.MaSP = int.Parse(dt.Rows[i]["MaSanPham"].ToString());
                sp.TenSP = dt.Rows[i]["TenSanPham"].ToString();
                sp.SoLuongTon = int.Parse(dt.Rows[i]["SoLuongTon"].ToString());
                sp.GiaBan = decimal.Parse(dt.Rows[i]["GiaBan"].ToString());
                sp.MaDVT = int.Parse(dt.Rows[i]["MaDonViTinh"].ToString());

                SPList.Add(sp);
            }

            return SPList;
        }
    }
}
